// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_MAP_BILLING_PD
// * CreateDate    : 2012/3/21 14:16:20
// * Creater       : CodeSmith
// * LastChangeDate: 2012/3/21 14:16:20
// * LastChanger   : 2012/3/21 14:16:20
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinMapBillingPd
    /// </summary>
    public partial class FinMapBillingPdBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinMapBillingPdEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinMapBillingPdEntity GetFinMapBillingPd(FinMapBillingPdEntity objFinMapBillingPdEntity)
        {
            return DataAccess.SelectSingle<FinMapBillingPdEntity>(objFinMapBillingPdEntity);
        }
        public static List<FinMapBillingPdEntity> GetByPaidDetailID(string paidDetailId)
        {
            if (string.IsNullOrEmpty(paidDetailId))
            {
                return null;
            }
            FinMapBillingPdEntity entity = new FinMapBillingPdEntity();
            entity.PaidDetailId = paidDetailId;
            return DataAccess.Select<FinMapBillingPdEntity>(entity);
        }
        public static List<FinMapBillingPdEntity> GetByBillingID(string billingId)
        {
            if (string.IsNullOrEmpty(billingId))
            {
                return null;
            }
            FinMapBillingPdEntity entity = new FinMapBillingPdEntity();
            entity.BillingId = billingId;
            return DataAccess.Select<FinMapBillingPdEntity>(entity);
        }

        public static List<InvImportOrderEntity> GetImportOrderByPaidDetailID(string paidDetailId)
        {
            if (string.IsNullOrEmpty(paidDetailId))
            {
                return null;
            }
            string sql = @"SELECT IMP.*
                            FROM FIN_MAP_BILLING_PD M
							INNER JOIN FIN_BILLING B ON B.BILLING_ID = M.BILLING_ID
							INNER JOIN FIN_MAP_BILLING_PA MAP ON MAP.BILLING_ID = B.BILLING_ID
                            INNER JOIN FIN_BILLING_PAID_APPLICATION BPA ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
                            INNER JOIN FIN_MAP_IO_BPA MAP2 ON MAP2.APPLICATION_ID = BPA.APPLICATION_ID
                            INNER JOIN INV_IMPORT_ORDER IMP ON IMP.IMPORT_ORDER_ID = MAP2.IMPORT_ORDER_ID
                            WHERE M.PAID_DETAIL_ID = '" + paidDetailId + "'";
            return DataAccess.Select<InvImportOrderEntity>(sql);
        }
        public static DataSet GetImportOrderByBilling(string billingIds)
        {
            if (string.IsNullOrEmpty(billingIds))
            {
                return null;
            }
            string sql = @"SELECT ITEM.*,O.ORDER_CODE,O.ORDER_DATE,P1.NAME_CN AS ORDER_PERSON_NAME,P.PRODUCT_CODE,P.PRODUCT_NAME
                            FROM INV_IMPORT_ITEM ITEM
						    INNER JOIN INV_IMPORT_ORDER O ON O.IMPORT_ORDER_ID = ITEM.IMPORT_ORDER_ID
							LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = ITEM.PRODUCT_ID
							LEFT JOIN FIN_MAP_IO_BPA MAP2 ON MAP2.IMPORT_ITEM_ID = ITEM.IMPORT_ITEM_ID
							LEFT JOIN FIN_BILLING_PAID_APPLICATION BPA ON BPA.APPLICATION_ID = MAP2.APPLICATION_ID
							LEFT JOIN FIN_MAP_BILLING_PA MAP ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
							LEFT JOIN FIN_BILLING B ON B.BILLING_ID = MAP.BILLING_ID
                            LEFT JOIN MST_PERSON P1 ON P1.PERSON_ID = O.ORDER_PERSON
                            LEFT JOIN MST_PERSON P2 ON P2.PERSON_ID = O.APPROVED_BY
                            WHERE B.BILLING_ID IN " + billingIds;
            return DataAccess.SelectDataSet(sql);
        }
        public static DataSet GetImportOrderByPdid(string pdid)
        {
            if (string.IsNullOrEmpty(pdid))
            {
                return null;
            }
            string sql = @"SELECT ITEM.*,O.ORDER_CODE,O.ORDER_DATE,P1.NAME_CN AS ORDER_PERSON_NAME,P.PRODUCT_CODE,P.PRODUCT_NAME
                            FROM INV_IMPORT_ITEM ITEM
						    INNER JOIN INV_IMPORT_ORDER O ON O.IMPORT_ORDER_ID = ITEM.IMPORT_ORDER_ID
							LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = ITEM.PRODUCT_ID
							LEFT JOIN FIN_MAP_IO_BPA MAP2 ON MAP2.IMPORT_ITEM_ID = ITEM.IMPORT_ITEM_ID
							LEFT JOIN FIN_BILLING_PAID_APPLICATION BPA ON BPA.APPLICATION_ID = MAP2.APPLICATION_ID
							LEFT JOIN FIN_MAP_BILLING_PA MAP ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
							LEFT JOIN FIN_BILLING B ON B.BILLING_ID = MAP.BILLING_ID
							LEFT JOIN FIN_MAP_BILLING_PD M ON M.BILLING_ID = B.BILLING_ID
                            LEFT JOIN MST_PERSON P1 ON P1.PERSON_ID = O.ORDER_PERSON
                            LEFT JOIN MST_PERSON P2 ON P2.PERSON_ID = O.APPROVED_BY
                            WHERE M.PAID_DETAIL_ID = '" + pdid + "'";
            return DataAccess.SelectDataSet(sql);
        }

        public static List<FinBillingPaidApplicationEntity> GetPaidAppByPaidDetailID(string paidDetailId)
        {
            if (string.IsNullOrEmpty(paidDetailId))
            {
                return null;
            }
            string sql = @"SELECT BPA.*
                            FROM FIN_MAP_BILLING_PD M
							INNER JOIN FIN_BILLING B ON B.BILLING_ID = M.BILLING_ID
							INNER JOIN FIN_MAP_BILLING_PA MAP ON MAP.BILLING_ID = B.BILLING_ID
                            INNER JOIN FIN_BILLING_PAID_APPLICATION BPA ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
                            WHERE M.PAID_DETAIL_ID = '" + paidDetailId + "'";
            return DataAccess.Select<FinBillingPaidApplicationEntity>(sql);
        }
        public static DataSet GetPayApplicationByBilling(string billingIds)
        {
            if (string.IsNullOrEmpty(billingIds))
            {
                return null;
            }
            string sql = @"SELECT BPA.*, S.SUPPLIER_NAME, P.NAME_CN AS APPLICATION_PERSON_NAME, C1.ITEM_NAME AS CURRENCY_NAME, C2.ITEM_NAME AS STATUS_NAME
                            FROM FIN_BILLING_PAID_APPLICATION BPA
							LEFT JOIN FIN_MAP_BILLING_PA MAP ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
							LEFT JOIN FIN_BILLING B ON B.BILLING_ID = MAP.BILLING_ID
                            LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = BPA.SUPPLIER_ID
                            LEFT JOIN MST_PERSON P ON P.PERSON_ID = BPA.APPLICATION_PERSON
							LEFT JOIN MST_COMMON_ITEM C1 ON C1.ITEM_CODE = BPA.CURRENCY
							LEFT JOIN MST_COMMON_ITEM C2 ON C2.ITEM_CODE = BPA.STATUS
                            WHERE B.BILLING_ID IN " + billingIds;
            return DataAccess.SelectDataSet(sql);
        }
        public static DataSet GetPayApplicationByPdid(string pdid)
        {
            if (string.IsNullOrEmpty(pdid))
            {
                return null;
            }
            string sql = @"SELECT BPA.*, S.SUPPLIER_NAME, P.NAME_CN AS APPLICATION_PERSON_NAME, C1.ITEM_NAME AS CURRENCY_NAME, C2.ITEM_NAME AS STATUS_NAME
                            FROM FIN_BILLING_PAID_APPLICATION BPA
							LEFT JOIN FIN_MAP_BILLING_PA MAP ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
							LEFT JOIN FIN_BILLING B ON B.BILLING_ID = MAP.BILLING_ID
							LEFT JOIN FIN_MAP_BILLING_PD M ON M.BILLING_ID = B.BILLING_ID
                            LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = BPA.SUPPLIER_ID
                            LEFT JOIN MST_PERSON P ON P.PERSON_ID = BPA.APPLICATION_PERSON
							LEFT JOIN MST_COMMON_ITEM C1 ON C1.ITEM_CODE = BPA.CURRENCY
							LEFT JOIN MST_COMMON_ITEM C2 ON C2.ITEM_CODE = BPA.STATUS
                            WHERE M.PAID_DETAIL_ID = '" + pdid + "'";
            return DataAccess.SelectDataSet(sql);
        }

        public static List<FinBillingEntity> GetBillingByPaidDetailID(string paidDetailId)
        {
            if (string.IsNullOrEmpty(paidDetailId))
            {
                return null;
            }
            string sql = @"SELECT B.*
                            FROM FIN_MAP_BILLING_PD M
							INNER JOIN FIN_BILLING B ON B.BILLING_ID = M.BILLING_ID
                            WHERE M.PAID_DETAIL_ID = '" + paidDetailId + "'";
            return DataAccess.Select<FinBillingEntity>(sql);
        }
        public static DataSet GetBillingByBilling(string billingIds)
        {
            if (string.IsNullOrEmpty(billingIds))
            {
                return null;
            }
            string sql = @"SELECT B.*, S.SUPPLIER_NAME, P.NAME_CN AS BILLING_PERSON_NAME, C1.ITEM_NAME AS CURRENCY_NAME, C2.ITEM_NAME AS STATUS_NAME
                            FROM FIN_BILLING B
                            LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = B.SUPPLIER_ID
                            LEFT JOIN MST_PERSON P ON P.PERSON_ID = B.BILLING_PERSON
							LEFT JOIN MST_COMMON_ITEM C1 ON C1.ITEM_CODE = B.CURRENCY
							LEFT JOIN MST_COMMON_ITEM C2 ON C2.ITEM_CODE = B.STATUS
                            WHERE B.BILLING_ID IN " + billingIds;
            return DataAccess.SelectDataSet(sql);
        }
        public static DataSet GetBillingByPdid(string pdid)
        {
            if (string.IsNullOrEmpty(pdid))
            {
                return null;
            }
            string sql = @"SELECT B.*, S.SUPPLIER_NAME, P.NAME_CN AS BILLING_PERSON_NAME, C1.ITEM_NAME AS CURRENCY_NAME, C2.ITEM_NAME AS STATUS_NAME
                            FROM FIN_BILLING B
							LEFT JOIN FIN_MAP_BILLING_PD M ON M.BILLING_ID = B.BILLING_ID
                            LEFT JOIN MST_SUPPLIER S ON S.SUPPLIER_ID = B.SUPPLIER_ID
                            LEFT JOIN MST_PERSON P ON P.PERSON_ID = B.BILLING_PERSON
							LEFT JOIN MST_COMMON_ITEM C1 ON C1.ITEM_CODE = B.CURRENCY
							LEFT JOIN MST_COMMON_ITEM C2 ON C2.ITEM_CODE = B.STATUS
                            WHERE M.PAID_DETAIL_ID = '" + pdid + "'";
            return DataAccess.SelectDataSet(sql);
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinMapBillingPdEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinMapBillingPd(FinMapBillingPdEntity objFinMapBillingPdEntity)
        {
            return DataAccess.Insert(objFinMapBillingPdEntity);
        }

        public static bool InsertFinMapBillingPd(List<FinMapBillingPdEntity> objFinMapBillingPdEntityList)
        {
            return DataAccess.Insert(objFinMapBillingPdEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinMapBillingPdEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinMapBillingPd(FinMapBillingPdEntity objFinMapBillingPdEntity)
        {
            return DataAccess.Update(objFinMapBillingPdEntity);
        }

        public static bool UpdateFinMapBillingPd(List<FinMapBillingPdEntity> objFinMapBillingPdEntityList)
        {
            return DataAccess.Update<FinMapBillingPdEntity>(objFinMapBillingPdEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinMapBillingPdEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinMapBillingPd(FinMapBillingPdEntity objFinMapBillingPdEntity)
        {
            return DataAccess.Delete(objFinMapBillingPdEntity);
        }

        public static bool DeleteFinMapBillingPd(List<FinMapBillingPdEntity> objFinMapBillingPdEntityList)
        {
            return DataAccess.Delete<FinMapBillingPdEntity>(objFinMapBillingPdEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinMapBillingPdAll()
        {
            return DataAccess.SelectAllDataSet<FinMapBillingPdEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinMapBillingPdEntity> GetFinMapBillingPdAllList()
        {
            return DataAccess.SelectAll<FinMapBillingPdEntity>();
        }
        #endregion
	}
	
	
}	

